<template>
    <div class="discount">
        <h2 class="title">10% off to get your start</h2>
        <p class="desc">Sign up to receive our latest news, offers, treats, and more, and receive a 10% discount for
            your next purchase.</p>
        <div class="inputBox">
            <el-input placeholder="Your Email address" v-model="email"></el-input>
            <div class="submit" @click="submit">
                <el-icon>
                    <Top />
                </el-icon>
            </div>
        </div>
        <p class="tips">*You can unsubscribe from our marketing emails at any time.</p>
    </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
import { addSubscribe } from '@/api/common';
const email = ref('');

const submit = async () => {
    //验证邮箱是否是正确的邮箱格式
    const reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
    if (!reg.test(email.value)) {
        ElMessage({
            message: 'Invalid Email',
            type: 'warning'
        });
        return;
    } else {
        //todo
        const params = {
            email: email.value
        };
        const res: any = await addSubscribe(params);
        if (res.code === '000000') {
            ElMessage({
                message: 'Discount received successfully, enter this email address on the payment order page to get the discount.',
                type: 'success'
            });
        } else {
            ElMessage({
                message: res.message,
                type: 'error'
            });
        }
    }
}
</script>
<style lang="scss" scoped>
.discount {
    margin: 0 34px;
    background: url('~@/assets/images/discount_bg.png') no-repeat;
    height: 535px;
    padding-left: 890px;
    overflow: hidden;
    color: #fff;

    .title {
        font-size: 48px;
        font-weight: 700;
        line-height: 86px;
        margin-top: 123px;
    }

    .desc {
        font-size: 24px;
        font-weight: 400;
        line-height: 32px;
    }

    .inputBox {
        margin-top: 50px;
        width: 600px;
        height: 73px;
        border-radius: 16px;
        background: #fff;
        display: flex;
        padding: 6px 8px;
        box-sizing: border-box;

        :deep(.el-input__wrapper) {
            box-shadow: none;
            font-size: 24px;
        }

        .submit {
            width: 69px;
            height: 61px;
            background: #846FC1;
            border-radius: 12px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;

            .el-icon {
                font-size: 40px;
            }
        }
    }

    .tips {
        margin-top: 18px;
        font-size: 20px;
        font-weight: 400;
        color: #A9A2A2;
    }
}
@media screen and (max-width: 750px) {
    .discount {
        margin: 0;
        padding: 0.9rem;
        height: 8.66rem;
        background: url('~@/assets/images/discount_bg_m.png') no-repeat;
        background-size: cover;

        .title {
            font-size: 0.48rem;
            line-height: 0.56rem;
            margin-top: 0;
        }

        .desc {
            font-size: 0.28rem;
            line-height: 0.32rem;
            margin-top: 0.2rem;
        }

        .inputBox {
            margin-top: 0.2rem;
            height: 0.73rem;
            border-radius: 0.16rem;
            padding: 0.06rem 0.12rem;
            width: 100%;

            :deep(.el-input__wrapper) {
                font-size: 0.24rem;
            }

            .submit {
                width: 0.69rem;
                height: 0.61rem;
                border-radius: 0.12rem;
                .el-icon {
                    font-size: 0.4rem;
                }
            }
        }

        .tips {
            margin-top: 0.16rem;
            font-size: 0.2rem;
        }
    }
    
}
</style>